package com.travelgroup.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.travelgroup.constant.RedisConstant;
import com.travelgroup.domain.entity.UserGroup;
import com.travelgroup.mapper.UserGroupMapper;
import com.travelgroup.service.IUserGroupService;
import com.travelgroup.utils.RedisUtil;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.util.concurrent.TimeUnit;

@Service
public class UserGroupServiceImpl extends ServiceImpl<UserGroupMapper, UserGroup>
        implements IUserGroupService {
    @Resource
    private RedisUtil redisUtil;

    /**
     * 获取Redis中数据
     * @param userId
     * @param groupId
     * @return
     */
    public UserGroup getByRedis(Long userId, Long groupId) {
        return redisUtil.queryById(RedisConstant.USER_GROUP_KEY + userId + ":", groupId, UserGroup.class,
                id -> this.lambdaQuery().eq(UserGroup::getGroupId, id)
                        .eq(UserGroup::getUserId, userId).one(),
                RedisConstant.CACHE_TTL, TimeUnit.MINUTES);
    }
}
